//#define _CRT_SECURE_NO_WARNINGS 1
//#include <stdio.h>
//#include <stddef.h>
//
//struct S
//{
//	char a;
//	int b;
//	char c;
//};
//
//#define OFFSETOF(type,name) ((size_t)(&((type*)0)->name))
//
//int main()
//{
//	printf("%d\n", offsetof(struct S, a));
//	printf("%d\n", offsetof(struct S, b));
//	printf("%d\n", offsetof(struct S, c));
//
//	printf("%d\n", OFFSETOF(struct S, a));
//	printf("%d\n", OFFSETOF(struct S, b));
//	printf("%d\n", OFFSETOF(struct S, c));
//
//	return 0;
//}
//

#include <stdio.h>
#include <stdlib.h>

#define MALLOC(type,num) (type*)malloc(sizeof(type) * num)

int main()
{

	int *pin = MALLOC(int, 3);
	pin[0] = 0;
	pin[1] = 1;
	pin[2] = 2;

	return 0;
}

int timeRequiredToBuy(int* tickets, int ticketsSize, int k)
{

    int time = 0;
    int n = tickets[k];

    for (int i = 0; i < ticketsSize; i++)
    {
        if (i <= k)
            time += tickets[k] >= tickets[i] ? tickets[i] : tickets[k];
        else
            time += tickets[k] - 1 >= tickets[i] ? tickets[i] : tickets[k] - 1;
    }

    return time;
}